from Enum import *
from AGDefines import *
from AGUtils import *
from ShiMen import *
from Role import *
from PinTu import *
from  ZhangHao import *
from TongJi import *



def test_role():

    dailyList = [
        'SuanGua',
        'PinTu',
        'ShiMen',
        'BaoTu',
        #'TongJi',
        #'HuanJing'
    ]
    """
    role1 = Role('m1',dailyList, 21503)
    role1.start()

    role2 = Role('m2', dailyList, 21513)
    role2.start()

    role3 = Role('m3', dailyList, 21523)
    role3.start()

    role4 = Role('m4', dailyList, 21533)
    role4.start()
    """
    role5 = Role('m5', dailyList, 21503)
    role5.start()

def test_huanjing():
    enum = Enum(21503)
    hj = HuanJing(enum)
    hj.KaiShi()

def test_TJJ2():

    path = '/Users/xuwanliang/Desktop/tj/'

    enum = Enum(21543)
    tj = TongJi(enum)

    for i in os.listdir(path):
        if i.endswith('png') is False:
            continue

        path_file = os.path.join(path, i)  # 取文件绝对路径
        logger.info(path_file)
        img = cv2.imread(path_file)
        if path_file is None:
            continue

        enum.frames += 1

        tj.findRenWuInList(img)

        cv2.waitKey()



def test_TJJ():

    path = '/Users/xuwanliang/Desktop/tj/'

    img = cv2.imread('/Users/xuwanliang/Desktop/tj/74.png')
    template1 = img[173:189, 631:730]

    template = getQueueTitle(template1)

    h0,w0,d0 = template.shape

    cv2.imshow("template", template)

    for i in os.listdir(path):
        if i.endswith('png') is False:
            continue

        path_file = os.path.join(path, i)  # 取文件绝对路径
        logger.info(path_file)
        img = cv2.imread(path_file)
        if path_file is None:
            continue

        img0 = img[112:309, 631:730]

        cv2.imshow("img0", img0)

        h,w,d = img0.shape

        img1 = getQueueTitle(img0)

        top_left, score = templateMatch(img1, template, 'testTJ')

        cv2.imshow("img1", img1)

        bottom_right = (top_left[0] + w0, top_left[1] + h0)
        cv2.rectangle(img0, top_left, bottom_right, 255, 2)

        cv2.imshow("imgres", img0)

        cv2.waitKey()

def testHuanJing():
    enum = Enum(21543)
    hj = TongJi(enum)
    img = cv2.imread('E:\devlop\DataSet\AutoGame\originTHYJ\HuanJing\\498.png')
    hj.test(img)


def test_shiMen():
    enum = Enum(21543)
    shim = ShiMen(enum)
    path = '{}/ShiMen/ZhuangYuan.png'.format(originPath)
    img = cv2.imread(path)
    if img is None:
        logger.info("cannot load "+path)
        return

    cv2.imshow("img",img)
    shim.selectRenWu(img)


    cv2.waitKey()


def test_zhanghao():



    enum = Enum(21543)
    zhangh = ZhangHao(enum)

    zhangh.switchHao('md1xwl', 'xwl123')





def test_pintu():
    #ZhiHuiPinTu
    #552

    enum = Enum(21543)

    """
    img = cv2.imread('/Users/xuwanliang/autogame/originTHYJ/PinTu/ZhiHuiPinTu.png')
    """

    img = enum.screenCap()

    if img is None:
        logger.info("can not load image")
        return

    pintu = PinTu()

    pintu.ZhiHuiPinPin(enum, img)


